<template>
	<view class="page home bgf7 c85">
		<image class="w-20 bg" src="/static/img/bg/home_bg.png"></image>
		<view class="aliC cff title pb16 rel" :style="{paddingTop: statusBar + 'px'}">管理端</view>
		<view class="flex flexC rel cff px15" @click="showShop">
			<image class="down" src="/static/img/icon/location.png" mode="widthFix"></image>
			<text class="px6">{{selectShop.name}}</text>
			<image class="right" src="/static/img/icon/right_nor.png" mode="widthFix"></image>
		</view>

		<scroll-view scroll-y="true" :style="{height: 'calc(100vh - 214rpx - ' + statusBar +'px)'}">
			<view class="bgff mx15 rel r7 pt16 pb24 mt18 shadow">
				<u-tabs lineColor="#EC80A8" :list="list" lineWidth="42" lineHeight="4" @click="switchTab"
					:itemStyle="{width: 'calc(33% - 22px)',paddingBottom: '5px'}"></u-tabs>

				<view class="flex flexC flexB aliC px26 mt10">
					<view @click="showTotal">
						<view class="bold6 fs17 c00">{{totalAmount}}</view>
						<view class="c85 mt2">总流水(元)</view>
					</view>
					<view>
						<view class="bold6 fs17 c00">{{bookAmount}}</view>
						<view class="c85 mt2">包厢预约(元)</view>
					</view>
					<view @click="balanceTip">
						<view class="bold6 fs17 c00">{{totalProfit}}</view>
						<view class="c85 mt2">现金收入(元)</view>
					</view>

				</view>

				<view class="flex flexC flexB aliC px26">
					<view>
						<view class="bold6 fs17 c00">{{tuanCheckAmount}}</view>
						<view class="c85 mt2">团购券抵扣(元)</view>
					</view>
					<view>
						<view class="bold6 fs17 c00" @click="mtTip">{{mtAmount}}</view>
						<view class="c85 mt2">美团核销(元)</view>
					</view>
					<view>
						<view class="bold6 fs17 c00" @click="douTip">{{douAmount}}</view>
						<view class="c85 mt2">抖音核销(元)</view>
					</view>
					<view>
						<view class="bold6 fs17 c00">{{taiAmount}}</view>
						<view class="c85 mt2">台球流水(元)</view>
					</view>

				</view>

				<view class="flex flexC flexB aliC px26">

					<view>
						<view class="bold6 fs17 c00">{{tuanAmount}}</view>
						<view class="c85 mt2">团购券购买(元)</view>
					</view>

					<view>
						<view class="bold6 fs17 c00">{{chargeAmount}}</view>
						<view class="c85 mt2">用户充值(元)</view>
					</view>

					<view>
						<view class="bold6 fs17 c00">{{balanceAmount}}</view>
						<view class="c85 mt2">余额抵扣(元)</view>
					</view>
					<view @click="orderTip">
						<view class="bold6 fs17 c00">{{totalOrder}}</view>
						<view class="c85 mt2">订单数(笔)</view>
					</view>

				</view>
			</view>
		
			
		</scroll-view>


		<!-- 店铺选择 -->
		<uni-popup ref="shopPicker" type="bottom">
			<shop-list @search="search" :list="shopList" @onSelectShop="onSelectShop" @close="onClose"></shop-list>
		</uni-popup>
		<tabbar></tabbar>
	</view>
</template>

<script>
	const statusBar = uni.getSystemInfoSync().statusBarHeight + 10;
	export default {
		data() {
			return {
				statusBar,
				list: [{
						name: '今天'
					},
					{
						name: '昨天'
					},
					{
						name: '本月'
					}
				],
				shopList: [],
				selectShop: null,
				keyword: '',
				currentIndex: 1,
				checkAmount: 0,
				totalAmount: 0,
				totalProfit: 0,
				totalOrder: 0,
				mdOrder: 0,
				deviceTotal: 0,
				deviceOnline: 0,
				deviceOffline: 0,
				balanceAmount: 0,
				tuanCheckAmount: 0,
				bookAmount: 0,
				tuanAmount: 0,
				chargeAmount: 0,
				mtAmount: 0,
				douAmount: 0,
				taiAmount: 0,
				air:-1


			}
		},
		onLoad() {

			this.getShopList();

		},
		onShow() {

		},
		
		onShareAppMessage(res) {
			console.log(res);
			if (res.from === 'button') { // 来自页面内分享按钮
				console.log(res.target)
			}
			return {
				title: '纷享时光管理端', //自定义分享标题
				path: '/pages/home/index', // '/pages/...'分享页面路径（打开分享时进入页），以/开头
			}
		},
		onShareTimeline(res) { //分享到朋友圈
			return {
				title: "纷享时光管理端",
				path: '/pages/home/index', // '/pages/...'分享页面路径（打开分享时进入页），以/开头
			}
		},
		methods: {
			
			
			balanceTip(){
				uni.showModal({
					title: "现金收入",
					content: "实际入账账户余额(不包含美团，抖音的核销)",
					showCancel: false
				})
			},
			
			orderTip(){
				uni.showModal({
					title: "订单",
					content: "包厢订单+台球订单",
					showCancel: false
				})
			},
			
			douTip(){
				uni.showModal({
					title: "抖音核销",
					content: "包厢抖音核销+台球抖音核销",
					showCancel: false
				})
			},
			mtTip(){
				uni.showModal({
					title: "美团核销",
					content: "包厢美团核销+台球美团核销",
					showCancel: false
				})
			},

			openAir() {
				if(this.air == 1){
					this.$refs.airPop.open();
				}else{
					this.$refs.airPop2.open();
				}
			},
			
			openAirSec(sec){
				this.$refs.airPop.close();
				
				let param = {
					shop_id: this.selectShop.id,
					sec:sec
				};
				let that = this;
				this.$api.openAir(param).then(res => {
				
					console.info(JSON.stringify(res));
					if (res.code == 1) {
						uni.showToast({
							title:'发送成功',
							icon:'none'				
						})
					} else {
						uni.showToast({
							title:res.msg,
							icon:'none'
					
						})
					}
				})
				
			},


			goTableOrder() {

				uni.navigateTo({
					url: '../order/tableIndex?selectShop=' + JSON.stringify(this.selectShop)
				})

			},

			goTable() {
				uni.navigateTo({
					url: '/other/table/list?selectShop=' + JSON.stringify(this.selectShop)
				})
			},

			goYouhui() {

				uni.navigateTo({
					url: '/other/youhui/couponList?selectShop=' + JSON.stringify(this.selectShop)
				})
			},
			
			clickKs(){
				uni.navigateTo({
					url: '/other/ks/couponList?selectShop=' + JSON.stringify(this.selectShop)
				})
			},

			goLive() {


				let param = {
					shop_id: this.selectShop.id,
				};
				let that = this;
				this.$api.getCamera(param).then(res => {

					console.info(JSON.stringify(res));
					if (res.code == 1) {
						uni.openEmbeddedMiniProgram({
							appId: 'wxf2b3a0262975d8c2',
							path: 'pages/live/live?accessToken=' + res.data.token + '&deviceSerial=' + res
								.data.device_no +
								'&channelNo=' + 1,
							success(res) {
								// 打开成功
							}
						})
					} else if (res.code == -2) {
						uni.showModal({
							title: "提示",
							content: "您尚未购买摄像头，请联系技术购买",
							showCancel: false,
							confirmText: "知道了"
						})
					} else {
						uni.showToast({
							title: res.msg
						})
					}
				})



			},

			goNotice() {
				uni.navigateTo({
					url: '/other/shop/notice?selectShop=' + JSON.stringify(this.selectShop)
				})
			},


			goVip() {
				uni.navigateTo({
					url: '/other/member/vipList?selectShop=' + JSON.stringify(this.selectShop)
				})
			},

			showTotal() {
				uni.showModal({
					title: "总流水",
					content: "包厢预定+团购券购买+台球金额+会员充值",
					showCancel: false
				})
			},

			showCheck() {
				uni.showModal({
					title: "核销金额",
					content: "美团核销：" + this.mtAmount + "元 " + "，抖音核销：" + this.douAmount + "元",
					showCancel: false
				})
			},

			goDou() {
				uni.navigateTo({
					url: '/other/dou/couponList'
				})
			},
			goDouBuy() {
				uni.navigateTo({
					url: '/other/dou/couponBuyList'
				})
			},


			goLine() {
				uni.navigateTo({
					url: '/other/charge/deviceManage'
				})
			},

			goLineOrder() {
				uni.navigateTo({
					url: '/other/charge/list'
				})
			},

			goMeituanBuy() {
				uni.navigateTo({
					url: '/other/meituan/couponBuyList'
				})
			},

			goMeituan() {
				uni.navigateTo({
					url: '/other/meituan/couponList'
				})
			},

			goOpen(type) {
				let param = {
					shop_id: this.selectShop.id,
					door: type
				};
				let that = this;
				this.$api.openNewDoor(param).then(res => {

					console.info(JSON.stringify(res));
					if (res.code == 1) {
						if (res.data == 2) {
							that.$refs.pop.open();
						}
					} else {

					}
				})

			},

			goChargeEdit() {
				uni.navigateTo({
					url: '/other/recharge/edit?selectShop=' + JSON.stringify(this.selectShop)
				})
			},

			goTuan() {
				uni.navigateTo({
					url: '/other/coupon/couponList?selectShop=' + JSON.stringify(this.selectShop)
				})
			},

			goTuanBuy() {
				uni.navigateTo({
					url: '/other/coupon/couponBuyList?selectShop=' + JSON.stringify(this.selectShop)
				})
			},

			goPackage() {
				uni.navigateTo({
					url: '../package/index?selectShop=' + JSON.stringify(this.selectShop)
				})
			},

			goDevice() {
				uni.navigateTo({
					url: '/other/device/device'
				})
			},

			goClean() {
				uni.navigateTo({
					url: '/other/staff/index?selectShop=' + JSON.stringify(this.selectShop)
				})
			},

			goCharge() {
				uni.navigateTo({
					url: '/other/recharge/list?selectShop=' + JSON.stringify(this.selectShop)

				})
			},

			shj() {
				uni.navigateToMiniProgram({
					appId: 'wx3c9509c6a53b4489',
					path: 'pages/index/index', // 不填默认首页
					extraData: {
						'data1': 'test'
					},
					success(res) {
						// 打开成功
					}
				})


			},

			wifi() {
				uni.navigateTo({
					url: '/other/device/wifi?selectShop=' + JSON.stringify(this.selectShop)
				})
			},

			goRoom() {
				uni.navigateTo({
					url: '../room/index?selectShop=' + JSON.stringify(this.selectShop)
				})
			},
			goStaff() {
				uni.navigateTo({
					url: '/other/staff/staff?selectShop=' + JSON.stringify(this.selectShop)
				})
			},

			goScan() {
				uni.scanCode({
					complete: function(res) {

					}
				})
			},
			goShop() {
				uni.navigateTo({
					url: '/other/shop/list'
				})
			},



			switchTab(e) {
				var name = e.name;
				if (name == '今天') {
					this.currentIndex = 1;
				} else if (name == '昨天') {
					this.currentIndex = 2;
				} else {
					this.currentIndex = 3;
				}
				this.getIndex();
				console.info(JSON.stringify(e));
			},

			showShop() {
				this.$refs.shopPicker.open();

			},
			search(value) {

				this.keyword = value;
				this.getShopList();
			},

			onSelectShop(item) {
				this.selectShop = item;
				uni.setStorageSync("selectShop", JSON.stringify(this.selectShop))
				this.$refs.shopPicker.close();
				this.getIndex();
				this.getShopIndexDevice();

			},

			getIndex() {
				let param = {
					shop_id: this.selectShop.id,
					date: this.currentIndex
				};
				let that = this;
				this.$api.v2ShopIndex(param).then(res => {

					console.info(JSON.stringify(res));
					if (res.code == 1) {

						that.totalAmount = res.data.totalAmount;
						that.totalOrder = res.data.totalOrder;
						that.checkAmount = res.data.checkAmount;
						that.totalProfit = res.data.totalProfit;
						that.balanceAmount = res.data.balanceAmount;
						that.tuanCheckAmount = res.data.tuanCheckAmount;
						that.checkAmount = res.data.checkAmount;
						that.bookAmount = res.data.bookAmount;
						that.tuanAmount = res.data.tuanAmount;
						that.chargeAmount = res.data.chargeAmount;
						that.mtAmount = res.data.mtAmount;
						that.douAmount = res.data.douAmount;
						that.mdOrder = res.data.mdOrder;
						that.taiAmount = res.data.taiAmount;
						that.air = res.data.air;

					} else {

					}
				})
			},

			getShopIndexDevice() {
				let param = {
					shop_id: this.selectShop.id,
				};
				let that = this;
				this.$api.getShopIndexDevice(param).then(res => {

					console.info(JSON.stringify(res));
					if (res.code == 1) {

						that.deviceTotal = res.data.total;
						that.deviceOnline = res.data.online;
						that.deviceOffline = res.data.offline;


					} else {

					}
				})
			},


			getShopList() {
				let param = {
					keyword: this.keyword,
					type:'invest'
				};
				let that = this;
				this.$api.getShopList(param).then(res => {

					console.info(JSON.stringify(res));
					if (res.code == 1) {
						that.shopList = res.data;
						if (that.shopList.length > 0) {
							that.selectShop = that.shopList[0];
							uni.setStorageSync("selectShop", JSON.stringify(that.selectShop))
							that.getIndex();
							that.getShopIndexDevice();

						}
					} else {

					}
				})
			},

			onClose() {
				this.$refs.shopPicker.close();
			}
		}
	}
</script>

<style lang="scss" scoped>
	.home {
		.down {
			width: 36rpx;
			height: 36rpx;
		}

		.bg {
			position: fixed;
			top: 0;
			left: 0;
			z-index: 0;
		}

		.rel {
			position: relative;
		}

		.right {
			width: 14rpx;
		}

		.w36 {
			width: 72rpx;
			height: 72rpx;
		}
	}

	.popup-content2 {
		background: #FFFFFF;

		.popup-btn {
			width: 100%;
			height: 100rpx;
			line-height: 100rpx;
			text-align: center;
			border-bottom: 1px solid #f5f5f5;
			background: #FFFFFF;
		}

		.button {
			width: 100%;
			height: 100rpx;
			line-height: 100rpx;
			text-align: center;
			border-bottom: 1px solid #f5f5f5;
			background: #FFFFFF;
			font-size: 11pt;
		}

		button::after {
			border: none;
		}

		.pt20 {
			border-bottom: 20rpx solid #f5f5f5;
		}
	}
</style>